<?php
class Archive{

	public function getArchive($id){
		$DB = new DB();
		$sql = "SELECT a.*,k.name FROM achivment a, kid k where a.kid_id = k.id And k.class_id='$id' order by date";
		return $DB->fetchAll($sql);
	}
	
	public function getAll(){
		$DB = new DB();
		$sql = "SELECT a.*,k.name FROM achivment a, kid k where a.kid_id = k.id order by date";
		return $DB->fetchAll($sql);	
	}
	
	public function getArchiveById($id){
		$DB = new DB();
		$sql = "SELECT a.*,k.name FROM achivment a, kid k where a.kid_id = k.id And a.id='$id' order by date desc";
		return $DB->fetchRow($sql);
	}
	
	public function getLastInsert(){
		$DB = new DB();
		$sql = "select max(id) as id from achivment ";
		return $DB->fetchRow($sql);
	}
	
	public function image($id,$filename){
		$sql = "UPDATE achivment set image=? where id='$id'";
		$field = array($filename);
		return DB::updateDB($sql,$field);
	}	
	
	public function addArchive($desc,$kid){
		$DB = new DB();
		$sql = "INSERT INTO `achivment` VALUES (:id,:kid_id,:image,:date,:desc)";
		$field = array(':id' => '',
					   ':kid_id' => $kid,
					   ':image' => '',
					   ':date' => date('Y-m-d'),
					   ':desc' => $desc
					  );	
		return $DB->updateDB($sql,$field);			
	}
	
	
	public function editArchive($id,$desc,$kid){
		$DB = new DB();
		$sql = "UPDATE `achivment` set kid_id=?,`desc`=? where id='$id'";
		$field = array($kid,$desc);
		return $DB->updateDB($sql,$field);	
	}
	
	public function delArchive($id){
		global $db;
		$sql = "delete from `achivment` where id='$id'";
		return $db->query($sql);		
	}
}
?>